Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Observability AI Assistant] migrate to inference client #197630 #199286

Conversation

arturoliduena
Copy link
Contributor

@arturoliduena arturoliduena commented Nov 7, 2024

Summary

Closes #183245

Closes #197630
[Observability AI Assistant] Partially migrate to inference client

replacing inferenceClient.chatComplete to observabilityAIAssistantClient.chat - observabilityAIAssistantClient.complete does a bunch of stuff on top of chat. keepping observabilityAIAssistantClient.chat as a wrapper for now because it also adds instrumentation and logging.

@arturoliduena arturoliduena added Team:Obs AI Assistant Observability AI Assistant backport:version Backport to applied version labels v8.17.0 labels Nov 7, 2024
@arturoliduena arturoliduena requested review from a team as code owners November 7, 2024 10:32
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Nov 7, 2024
Copy link
Contributor

github-actions bot commented Nov 7, 2024

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@arturoliduena arturoliduena force-pushed the 197630-o11y-ai-assistant-inferenceClient-migration branch 2 times, most recently from 60177d0 to a3b2644 Compare November 7, 2024 14:46
@pgayvallet pgayvallet requested a review from a team November 8, 2024 07:22
@arturoliduena arturoliduena marked this pull request as draft November 8, 2024 08:34
@arturoliduena arturoliduena added the release_note:skip Skip the PR/issue when compiling release notes label Nov 8, 2024
throw createInternalServerError(
`${executeResult?.message} - ${executeResult?.serviceMessage}`
);
): Observable<ChatCompletionEvent> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we encapsulate the event type from the inference client here, and convert it into ChatCompletionChunkEvent. We should eventually completely drop ChatCompletionChunkEvent in favor of the inference plugin's types, but that means that we need to make changes in many places, and there's some stuff that isn't supported yet by the Inference plugin's types. Until that happens, I think we should limit the blast radius and stick to our own types where we can - which should be everywhere except for the implementation of this function, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, I will use ChatEvent to maintain compatibility with existing types (ChatCompletionChunkEvent, and TokenCountEvent) and adding InferenceChatCompletionChunkEvent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, what I mean is that we only have ChatCompletionChunkEvent (which is exclusive to the Obs AI Assistant). Any event from the Inference client is ideally not exposed via the chat method. So the signature of the chat method should stay the same, and existing types as well. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I’ll keep the ChatCompletionChunkEvent as the main event type for the ObservabilityAIAssistantClient.chat method to ensure we don’t expose any inference-client-specific types directly. I’ll handle the conversion internally within the implementation, encapsulating the inference client events as needed without altering the existing method signature or exposing the InferenceChatCompletionChunkEvent.

  • Solution:
    Within the pipe, we’ll add a mapping step to convert any incoming InferenceChatCompletionChunkEvent to a ChatCompletionChunkEvent type. should I do it for all the event emitted from inferenceClient.complete method?
    for these 3 inference client events:
export type ChatCompletionEvent<TToolOptions extends ToolOptions = ToolOptions> =
  | ChatCompletionChunkEvent
  | ChatCompletionTokenCountEvent
  | ChatCompletionMessageEvent<TToolOptions>;

@arturoliduena arturoliduena force-pushed the 197630-o11y-ai-assistant-inferenceClient-migration branch 3 times, most recently from c59ff8b to df2a179 Compare November 13, 2024 11:04
tools,
})
).pipe(
convertInferenceEventsToStreamingEvents(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgieselaar
convertInferenceEventsToStreamingEvents converts any InferenceChatCompletionEvent types to their corresponding StreamingChatResponseEvent types, such as ChatCompletionChunkEvent, TokenCountEvent, ensuring we maintain compatibility with existing event types. This keeps the ObservabilityAIAssistantClient.chat method’s signature intact and avoids exposing inference-client-specific types directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++, this looks good!

@arturoliduena arturoliduena force-pushed the 197630-o11y-ai-assistant-inferenceClient-migration branch from df2a179 to 200217b Compare November 26, 2024 09:24
@arturoliduena arturoliduena marked this pull request as ready for review November 26, 2024 09:26
@arturoliduena arturoliduena requested a review from a team as a code owner November 26, 2024 10:13
Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana.jsonc LGTM

@arturoliduena arturoliduena force-pushed the 197630-o11y-ai-assistant-inferenceClient-migration branch 5 times, most recently from ef466d1 to 578d51e Compare December 3, 2024 09:44
}

await simulator.tokenCount({ completion: 20, prompt: 33, total: 53 });
Copy link
Member

@sorenlouv sorenlouv Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manually calculate these? If the input chunks are changed, will the token counts go out of sync without us noticing? Theres nothing that actually counts the tokens and require the token count to match?

arturoliduena and others added 13 commits December 9, 2024 08:55
…create_openai_chunk.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…nt/server/service/client/operators/convert_inference_events_to_streaming_events.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…nt/server/service/client/operators/convert_inference_events_to_streaming_events.ts

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
@arturoliduena arturoliduena force-pushed the 197630-o11y-ai-assistant-inferenceClient-migration branch from 1040c29 to 2355ca4 Compare December 9, 2024 07:55
@elasticmachine
Copy link
Contributor

elasticmachine commented Dec 9, 2024

💚 Build Succeeded

  • Buildkite Build
  • Commit: 2355ca4
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-199286-2355ca46d51c

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
observabilityAIAssistant 294 296 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observabilityAIAssistant 48.1KB 48.3KB +206.0B
Unknown metric groups

API count

id before after diff
observabilityAIAssistant 296 298 +2

History

@arturoliduena arturoliduena merged commit df0dfa5 into elastic:main Dec 9, 2024
11 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12234966215

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 9, 2024
… (elastic#199286)

## Summary

Closes elastic#183245

Closes elastic#197630
[Observability AI Assistant] Partially migrate to inference client

replacing `inferenceClient.chatComplete` to
`observabilityAIAssistantClient.chat` -
`observabilityAIAssistantClient.complete` does a bunch of stuff on top
of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper
for now because it also adds instrumentation and logging.

(cherry picked from commit df0dfa5)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 9, 2024
#199286) (#203399)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Observability AI Assistant] migrate to inference client #197630
(#199286)](#199286)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Arturo
Lidueña","email":"arturo.liduena@elastic.co"},"sourceCommit":{"committedDate":"2024-12-09T11:46:31Z","message":"[Observability
AI Assistant] migrate to inference client #197630 (#199286)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630
\r\n[Observability AI Assistant] Partially migrate to inference client
\r\n\r\nreplacing `inferenceClient.chatComplete`
to\r\n`observabilityAIAssistantClient.chat`
-\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on
top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a
wrapper\r\nfor now because it also adds instrumentation and
logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v8.18.0"],"title":"[Observability
AI Assistant] migrate to inference client
#197630","number":199286,"url":"https://github.com/elastic/kibana/pull/199286","mergeCommit":{"message":"[Observability
AI Assistant] migrate to inference client #197630 (#199286)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630
\r\n[Observability AI Assistant] Partially migrate to inference client
\r\n\r\nreplacing `inferenceClient.chatComplete`
to\r\n`observabilityAIAssistantClient.chat`
-\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on
top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a
wrapper\r\nfor now because it also adds instrumentation and
logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199286","number":199286,"mergeCommit":{"message":"[Observability
AI Assistant] migrate to inference client #197630 (#199286)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630
\r\n[Observability AI Assistant] Partially migrate to inference client
\r\n\r\nreplacing `inferenceClient.chatComplete`
to\r\n`observabilityAIAssistantClient.chat`
-\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on
top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a
wrapper\r\nfor now because it also adds instrumentation and
logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Arturo Lidueña <arturo.liduena@elastic.co>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
… (elastic#199286)

## Summary

Closes elastic#183245

Closes elastic#197630 
[Observability AI Assistant] Partially migrate to inference client 

replacing `inferenceClient.chatComplete` to
`observabilityAIAssistantClient.chat` -
`observabilityAIAssistantClient.complete` does a bunch of stuff on top
of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper
for now because it also adds instrumentation and logging.
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/kibana that referenced this pull request Dec 10, 2024
… (elastic#199286)

## Summary

Closes elastic#183245

Closes elastic#197630 
[Observability AI Assistant] Partially migrate to inference client 

replacing `inferenceClient.chatComplete` to
`observabilityAIAssistantClient.chat` -
`observabilityAIAssistantClient.complete` does a bunch of stuff on top
of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper
for now because it also adds instrumentation and logging.
mykolaharmash pushed a commit to mykolaharmash/kibana that referenced this pull request Dec 11, 2024
… (elastic#199286)

## Summary

Closes elastic#183245

Closes elastic#197630 
[Observability AI Assistant] Partially migrate to inference client 

replacing `inferenceClient.chatComplete` to
`observabilityAIAssistantClient.chat` -
`observabilityAIAssistantClient.complete` does a bunch of stuff on top
of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper
for now because it also adds instrumentation and logging.
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
… (elastic#199286)

## Summary

Closes elastic#183245

Closes elastic#197630 
[Observability AI Assistant] Partially migrate to inference client 

replacing `inferenceClient.chatComplete` to
`observabilityAIAssistantClient.chat` -
`observabilityAIAssistantClient.complete` does a bunch of stuff on top
of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper
for now because it also adds instrumentation and logging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:Obs AI Assistant Observability AI Assistant v8.18.0 v9.0.0
Projects
None yet
8 participants